import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CouponTemplateVO, CouponTemplateForm, CouponTemplateQuery } from '@/api/tearoom/couponTemplate/types';

/**
 * 查询优惠劵模板列表
 * @param query
 * @returns {*}
 */

export const listCouponTemplate = (query?: CouponTemplateQuery): AxiosPromise<CouponTemplateVO[]> => {
  return request({
    url: '/tearoom/couponTemplate/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询优惠劵模板详细
 * @param id
 */
export const getCouponTemplate = (id: string | number): AxiosPromise<CouponTemplateVO> => {
  return request({
    url: '/tearoom/couponTemplate/' + id,
    method: 'get'
  });
};

/**
 * 新增优惠劵模板
 * @param data
 */
export const addCouponTemplate = (data: CouponTemplateForm) => {
  return request({
    url: '/tearoom/couponTemplate',
    method: 'post',
    data: data
  });
};

/**
 * 修改优惠劵模板
 * @param data
 */
export const updateCouponTemplate = (data: CouponTemplateForm) => {
  return request({
    url: '/tearoom/couponTemplate',
    method: 'put',
    data: data
  });
};

/**
 * 修改优惠卷状态
 * @param data
 */
export const changeCouponStatus = (id: number | string, status: number) => {
  const data = {
    id,
    status
  };
  return request({
    url: '/tearoom/couponTemplate/changeStatus',
    method: 'put',
    data: data
  });
};

/**
 * 删除优惠劵模板
 * @param id
 */
export const delCouponTemplate = (id: string | number | Array<string | number>) => {
  return request({
    url: '/tearoom/couponTemplate/' + id,
    method: 'delete'
  });
};
